import { Injectable } from '@angular/core';
import { SERVERS_NAME } from '../../../config/config';
import { HttpService } from '../../../core/http.service';
import { CommHttpService } from '../../../core/comm.http.service';
import { PaginationUtils } from '../../../utils/paginationUtils';
import { PageEntity } from '../../../core/domain/page.entity';

@Injectable()
export class RoomManageService extends CommHttpService {

  protected preUrl = `${SERVERS_NAME.SECURITY_SERVER}sys/room/`;

  constructor(protected http: HttpService) {
    super(http);
  }

  /**
   * 分页配备字段
   * @param  list 关键字匹配值
   * @param pageInfo 分页条件
   */
  pageFarm(pageInfo: PageEntity, list: Array<{ name?: string, value?: string }>): void {
    list.forEach(item => {
      if (!item.value) {
        delete pageInfo.filters[item.name];
        return;
      } else {
        PaginationUtils.filter(pageInfo, item.name, item.value, 'contains');
      }
    });
  }

  roomTypeList() {
    return this.http.post({}, `${SERVERS_NAME.SECURITY_SERVER}sys/dictionary/listByType/room`);
  }

  // 关联-查询教务房间下拉
  getJwList() {
    return this.http.post({}, `${this.preUrl}jw/findList`);
  }

  // 关联-保存前回显选中
  findSelectedList(data) {
    return this.http.post(data, `${this.preUrl}jw/findSelectedList`);
  }

  // 关联-保存
  saveJwList(data) {
    return this.http.post(data, `${this.preUrl}jw/saveSelectedList`);
  }
}
